/*
 * Academic License - for use in teaching, academic research, and meeting
 * course requirements at degree granting institutions only.  Not for
 * government, commercial, or other organizational use.
 *
 * File: LBG_model.c
 *
 * Code generated for Simulink model 'LBG_model'.
 *
 * Model version                  : 2.84
 * Simulink Coder version         : 9.8 (R2022b) 13-May-2022
 * C/C++ source code generated on : Sun Sep 21 15:34:19 2025
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "LBG_model.h"
#include "rtwtypes.h"
#include "LBG_model_private.h"
#include <math.h>
#include "rt_nonfinite.h"
#include <float.h>
#include "rt_defines.h"

/* Named constants for Chart: '<S2>/Chart' */
#define LBG_model_IN_CLL               ((uint8_T)1U)
#define LBG_model_IN_CLL1              ((uint8_T)2U)
#define LBG_model_IN_Init              ((uint8_T)3U)
#define LBG_model_IN_OPL               ((uint8_T)4U)
#define LBG_model_IN_OPL1              ((uint8_T)5U)

/* Exported data definition */

/* Definition for custom storage class: Struct */
rt_Simulink_Struct_type rt_Simulink_Struct;

/* Block signals (default storage) */
B_LBG_model_T LBG_model_B;

/* Block states (default storage) */
DW_LBG_model_T LBG_model_DW;

/* Real-time model */
static RT_MODEL_LBG_model_T LBG_model_M_;
RT_MODEL_LBG_model_T *const LBG_model_M = &LBG_model_M_;
static void rate_scheduler(void);

/*
 *         This function updates active task flag for each subrate.
 *         The function is called at model base rate, hence the
 *         generated code self-manages all its subrates.
 */
static void rate_scheduler(void)
{
  /* Compute which subrates run during the next base time step.  Subrates
   * are an integer multiple of the base rate counter.  Therefore, the subtask
   * counter is reset when it reaches its limit (zero means run).
   */
  (LBG_model_M->Timing.TaskCounters.TID[1])++;
  if ((LBG_model_M->Timing.TaskCounters.TID[1]) > 19) {/* Sample time: [0.001s, 0.0s] */
    LBG_model_M->Timing.TaskCounters.TID[1] = 0;
  }

  (LBG_model_M->Timing.TaskCounters.TID[2])++;
  if ((LBG_model_M->Timing.TaskCounters.TID[2]) > 199) {/* Sample time: [0.01s, 0.0s] */
    LBG_model_M->Timing.TaskCounters.TID[2] = 0;
  }
}

/*
 * Output and update for atomic system:
 *    '<S12>/MATLAB cos'
 *    '<S14>/MATLAB cos'
 */
void LBG_model_MATLABcos(real32_T rtu_u, real32_T *rty_y)
{
  *rty_y = rtu_u;
  *rty_y = cosf(*rty_y);
}

/*
 * Output and update for atomic system:
 *    '<S12>/MATLAB sin'
 *    '<S14>/MATLAB sin'
 */
void LBG_model_MATLABsin(real32_T rtu_u, real32_T *rty_y)
{
  *rty_y = rtu_u;
  *rty_y = sinf(*rty_y);
}

real32_T rt_modf_snf(real32_T u0, real32_T u1)
{
  real32_T y;
  y = u0;
  if (u1 == 0.0F) {
    if (u0 == 0.0F) {
      y = u1;
    }
  } else if (rtIsNaNF(u0) || rtIsNaNF(u1) || rtIsInfF(u0)) {
    y = (rtNaNF);
  } else if (u0 == 0.0F) {
    y = 0.0F / u1;
  } else if (rtIsInfF(u1)) {
    if ((u1 < 0.0F) != (u0 < 0.0F)) {
      y = u1;
    }
  } else {
    boolean_T yEq;
    y = fmodf(u0, u1);
    yEq = (y == 0.0F);
    if ((!yEq) && (u1 > floorf(u1))) {
      real32_T q;
      q = fabsf(u0 / u1);
      yEq = !(fabsf(q - floorf(q + 0.5F)) > FLT_EPSILON * q);
    }

    if (yEq) {
      y = u1 * 0.0F;
    } else if ((u0 < 0.0F) != (u1 < 0.0F)) {
      y += u1;
    }
  }

  return y;
}

real32_T rt_atan2f_snf(real32_T u0, real32_T u1)
{
  real32_T y;
  if (rtIsNaNF(u0) || rtIsNaNF(u1)) {
    y = (rtNaNF);
  } else if (rtIsInfF(u0) && rtIsInfF(u1)) {
    int32_T tmp;
    int32_T tmp_0;
    if (u0 > 0.0F) {
      tmp = 1;
    } else {
      tmp = -1;
    }

    if (u1 > 0.0F) {
      tmp_0 = 1;
    } else {
      tmp_0 = -1;
    }

    y = atan2f((real32_T)tmp, (real32_T)tmp_0);
  } else if (u1 == 0.0F) {
    if (u0 > 0.0F) {
      y = RT_PIF / 2.0F;
    } else if (u0 < 0.0F) {
      y = -(RT_PIF / 2.0F);
    } else {
      y = 0.0F;
    }
  } else {
    y = atan2f(u0, u1);
  }

  return y;
}

/* Model step function */
void LBG_Arctan_FOC_step(real32_T arg_Target_Speed, real32_T arg_Iabc[3],
  real32_T arg_Real_Theta, real32_T arg_Vabc_PU[3])
{
  real32_T T1;
  real32_T T2;
  real32_T beta;
  real32_T rtb_Delay2;
  real32_T rtb_Delay3;
  real32_T rtb_Saturation;
  real32_T rtb_Saturation_l;
  real32_T rtb_Saturation_o;
  real32_T rtb_Sum2;
  real32_T rtb_Sum3;
  real32_T rtb_Sum_b;
  real32_T rtb_Tcmp3;
  real32_T rtb_Vbeta;
  real32_T rtb_algDD_o1_m;
  real32_T rtb_ibeta;
  real32_T ta;
  uint32_T elapsedTicks;
  uint16_T rtb_Get_Integer;
  int8_T rtPrevAction;
  int8_T tmp;
  UNUSED_PARAMETER(arg_Real_Theta);
  if (LBG_model_M->Timing.TaskCounters.TID[2] == 0) {
    /* S-Function (fcgen): '<S1>/Function-Call Generator5' incorporates:
     *  SubSystem: '<S1>/10ms_Task'
     */
    /* Chart: '<S2>/Chart' incorporates:
     *  Inport: '<Root>/Target_Speed'
     */
    elapsedTicks = LBG_model_M->Timing.clockTick2 - LBG_model_DW.previousTicks;
    LBG_model_DW.previousTicks = LBG_model_M->Timing.clockTick2;
    if (LBG_model_DW.temporalCounter_i1 + elapsedTicks <= 63U) {
      LBG_model_DW.temporalCounter_i1 = (uint8_T)
        (LBG_model_DW.temporalCounter_i1 + elapsedTicks);
    } else {
      LBG_model_DW.temporalCounter_i1 = 63U;
    }

    if (LBG_model_DW.is_active_c1_LBG_model == 0U) {
      LBG_model_DW.is_active_c1_LBG_model = 1U;
      LBG_model_DW.is_c1_LBG_model = LBG_model_IN_Init;
      LBG_model_DW.temporalCounter_i1 = 0U;
      rt_Simulink_Struct.Motor_state = 0;
    } else {
      switch (LBG_model_DW.is_c1_LBG_model) {
       case LBG_model_IN_CLL:
        rt_Simulink_Struct.Motor_state = 2;
        LBG_model_DW.time = 0.0;
        break;

       case LBG_model_IN_CLL1:
        rt_Simulink_Struct.Motor_state = 2;
        LBG_model_DW.time = 0.0;
        break;

       case LBG_model_IN_Init:
        if ((LBG_model_DW.temporalCounter_i1 >= 50U) && (arg_Target_Speed >=
             0.0F)) {
          LBG_model_DW.is_c1_LBG_model = LBG_model_IN_OPL;
          rt_Simulink_Struct.Motor_state = 1;
          LBG_model_DW.time++;
        } else if ((LBG_model_DW.temporalCounter_i1 >= 50U) && (arg_Target_Speed
                    < 0.0F)) {
          LBG_model_DW.is_c1_LBG_model = LBG_model_IN_OPL1;
          rt_Simulink_Struct.Motor_state = 3;
          LBG_model_DW.time++;
        } else {
          rt_Simulink_Struct.Motor_state = 0;
        }
        break;

       case LBG_model_IN_OPL:
        if ((LBG_model_DW.time > 100.0) && (LBG_model_DW.Delay_DSTATE > 900.0F))
        {
          LBG_model_DW.is_c1_LBG_model = LBG_model_IN_CLL;
          rt_Simulink_Struct.Motor_state = 2;
          LBG_model_DW.time = 0.0;
        } else {
          rt_Simulink_Struct.Motor_state = 1;
          LBG_model_DW.time++;
        }
        break;

       default:
        /* case IN_OPL1: */
        if ((LBG_model_DW.time > 100.0) && (LBG_model_DW.Delay_DSTATE < -900.0F))
        {
          LBG_model_DW.is_c1_LBG_model = LBG_model_IN_CLL1;
          rt_Simulink_Struct.Motor_state = 2;
          LBG_model_DW.time = 0.0;
        } else {
          rt_Simulink_Struct.Motor_state = 3;
          LBG_model_DW.time++;
        }
        break;
      }
    }

    /* End of Chart: '<S2>/Chart' */
    /* End of Outputs for S-Function (fcgen): '<S1>/Function-Call Generator5' */
  }

  if (LBG_model_M->Timing.TaskCounters.TID[1] == 0) {
    /* S-Function (fcgen): '<S1>/Function-Call Generator3' incorporates:
     *  SubSystem: '<S1>/Speed_Control'
     */
    /* Outputs for Enabled SubSystem: '<S4>/Subsystem' incorporates:
     *  EnablePort: '<S370>/Enable'
     */
    /* RelationalOperator: '<S369>/Compare' incorporates:
     *  Constant: '<S369>/Constant'
     */
    if (rt_Simulink_Struct.Motor_state == 2) {
      if (!LBG_model_DW.Subsystem_MODE) {
        LBG_model_DW.Subsystem_RESET_ELAPS_T = true;

        /* Enable for DiscreteIntegrator: '<S403>/Integrator' */
        LBG_model_DW.Integrator_SYSTEM_ENABLE_h = 1U;
        LBG_model_DW.Subsystem_MODE = true;
      }

      if (LBG_model_DW.Subsystem_RESET_ELAPS_T) {
        elapsedTicks = 0U;
      } else {
        elapsedTicks = LBG_model_M->Timing.clockTick1 -
          LBG_model_DW.Subsystem_PREV_T;
      }

      LBG_model_DW.Subsystem_PREV_T = LBG_model_M->Timing.clockTick1;
      LBG_model_DW.Subsystem_RESET_ELAPS_T = false;

      /* SignalConversion generated from: '<S370>/Id_Ref' */
      LBG_model_B.OutportBufferForId_Ref = LBG_model_ConstB.Constant;

      /* Sum: '<S370>/Sum' incorporates:
       *  Inport: '<Root>/Target_Speed'
       */
      rtb_Sum_b = arg_Target_Speed - LBG_model_DW.Delay_DSTATE;

      /* DiscreteIntegrator: '<S403>/Integrator' */
      if (LBG_model_DW.Integrator_SYSTEM_ENABLE_h == 0) {
        /* DiscreteIntegrator: '<S403>/Integrator' */
        LBG_model_DW.Integrator_DSTATE_cq += 0.001F * (real32_T)elapsedTicks *
          LBG_model_DW.Integrator_PREV_U_a;
      }

      /* End of DiscreteIntegrator: '<S403>/Integrator' */

      /* Sum: '<S412>/Sum' incorporates:
       *  Gain: '<S408>/Proportional Gain'
       */
      LBG_model_B.Saturation = 4.59839575E-5F * rtb_Sum_b +
        LBG_model_DW.Integrator_DSTATE_cq;

      /* Saturate: '<S410>/Saturation' */
      if (LBG_model_B.Saturation > 3.26732683F) {
        /* Sum: '<S412>/Sum' incorporates:
         *  Saturate: '<S410>/Saturation'
         */
        LBG_model_B.Saturation = 3.26732683F;
      } else if (LBG_model_B.Saturation < -3.26732683F) {
        /* Sum: '<S412>/Sum' incorporates:
         *  Saturate: '<S410>/Saturation'
         */
        LBG_model_B.Saturation = -3.26732683F;
      }

      /* End of Saturate: '<S410>/Saturation' */

      /* Update for DiscreteIntegrator: '<S403>/Integrator' incorporates:
       *  Gain: '<S400>/Integral Gain'
       */
      LBG_model_DW.Integrator_SYSTEM_ENABLE_h = 0U;
      LBG_model_DW.Integrator_PREV_U_a = 0.000727070204F * rtb_Sum_b;
    } else {
      LBG_model_DW.Subsystem_MODE = false;
    }

    /* End of RelationalOperator: '<S369>/Compare' */
    /* End of Outputs for SubSystem: '<S4>/Subsystem' */
    /* End of Outputs for S-Function (fcgen): '<S1>/Function-Call Generator3' */
  }

  /* S-Function (fcgen): '<S1>/Function-Call Generator4' incorporates:
   *  SubSystem: '<S1>/FOC'
   */
  if (LBG_model_DW.FOC_RESET_ELAPS_T) {
    elapsedTicks = 0U;
  } else {
    elapsedTicks = LBG_model_M->Timing.clockTick0 - LBG_model_DW.FOC_PREV_T;
  }

  /* Update for IfAction SubSystem: '<S9>/Switch Case Action Subsystem3' incorporates:
   *  ActionPort: '<S368>/Action Port'
   */
  /* Update for IfAction SubSystem: '<S9>/Switch Case Action Subsystem1' incorporates:
   *  ActionPort: '<S366>/Action Port'
   */
  /* Outputs for IfAction SubSystem: '<S9>/Switch Case Action Subsystem3' incorporates:
   *  ActionPort: '<S368>/Action Port'
   */
  /* Outputs for IfAction SubSystem: '<S9>/Switch Case Action Subsystem1' incorporates:
   *  ActionPort: '<S366>/Action Port'
   */
  /* SwitchCase: '<S9>/Switch Case' */
  LBG_model_DW.FOC_PREV_T = LBG_model_M->Timing.clockTick0;

  /* End of Outputs for SubSystem: '<S9>/Switch Case Action Subsystem1' */
  /* End of Outputs for SubSystem: '<S9>/Switch Case Action Subsystem3' */
  /* End of Update for SubSystem: '<S9>/Switch Case Action Subsystem1' */
  /* End of Update for SubSystem: '<S9>/Switch Case Action Subsystem3' */
  LBG_model_DW.FOC_RESET_ELAPS_T = false;

  /* MATLAB Function: '<S7>/Clark2' incorporates:
   *  Inport: '<Root>/Iabc'
   */
  rtb_Sum_b = arg_Iabc[0] * 2.0F / 3.0F - (arg_Iabc[1] + arg_Iabc[2]) / 3.0F;
  rtb_ibeta = (arg_Iabc[1] - arg_Iabc[2]) * 1.73205078F / 3.0F;

  /* Delay: '<S11>/Delay2' */
  rtb_Delay2 = LBG_model_DW.Delay2_DSTATE;

  /* Saturate: '<S10>/Saturation' incorporates:
   *  Delay: '<S10>/Delay'
   */
  if (LBG_model_DW.Delay_DSTATE_g > 14660.7656F) {
    rtb_Sum2 = 14660.7656F;
  } else if (LBG_model_DW.Delay_DSTATE_g < -14660.7656F) {
    rtb_Sum2 = -14660.7656F;
  } else {
    rtb_Sum2 = LBG_model_DW.Delay_DSTATE_g;
  }

  /* End of Saturate: '<S10>/Saturation' */

  /* Delay: '<S11>/Delay3' */
  rtb_Delay3 = LBG_model_DW.Delay3_DSTATE;

  /* Sum: '<S11>/Add10' incorporates:
   *  Constant: '<S11>/Constant2'
   *  Delay: '<S11>/Delay'
   *  Delay: '<S11>/Delay2'
   *  Delay: '<S11>/Delay3'
   *  Gain: '<S11>/Gain'
   *  Product: '<S11>/Product1'
   *  Product: '<S11>/Product8'
   *  Sum: '<S11>/Add1'
   */
  LBG_model_DW.Delay2_DSTATE = (LBG_model_DW.Delay2_DSTATE - 5.0E-5F * rtb_Sum2 *
    LBG_model_DW.Delay3_DSTATE) + (LBG_model_DW.Delay_DSTATE_p - rtb_Sum_b) *
    1.04244959F;

  /* Sum: '<S11>/Add3' incorporates:
   *  Constant: '<S11>/Constant3'
   *  Delay: '<S11>/Delay1'
   *  Delay: '<S11>/Delay3'
   *  Gain: '<S11>/Gain1'
   *  Product: '<S11>/Product2'
   *  Product: '<S11>/Product3'
   *  Sum: '<S11>/Add2'
   */
  LBG_model_DW.Delay3_DSTATE = (5.0E-5F * rtb_Sum2 * rtb_Delay2 +
    LBG_model_DW.Delay3_DSTATE) + (LBG_model_DW.Delay1_DSTATE - rtb_ibeta) *
    1.04244959F;

  /* SwitchCase: '<S9>/Switch Case' */
  rtPrevAction = LBG_model_DW.SwitchCase_ActiveSubsystem;
  LBG_model_DW.SwitchCase_ActiveSubsystem = -1;
  switch (rt_Simulink_Struct.Motor_state) {
   case 0:
    LBG_model_DW.SwitchCase_ActiveSubsystem = 0;
    break;

   case 1:
    LBG_model_DW.SwitchCase_ActiveSubsystem = 1;
    break;

   case 2:
    LBG_model_DW.SwitchCase_ActiveSubsystem = 2;
    break;

   case 3:
    LBG_model_DW.SwitchCase_ActiveSubsystem = 3;
    break;
  }

  switch (LBG_model_DW.SwitchCase_ActiveSubsystem) {
   case 0:
    /* Outputs for IfAction SubSystem: '<S9>/Switch Case Action Subsystem' incorporates:
     *  ActionPort: '<S365>/Action Port'
     */
    /* Merge: '<S9>/Merge' incorporates:
     *  Constant: '<S365>/Constant1'
     *  SignalConversion generated from: '<S365>/Id_Ref'
     */
    rt_Simulink_Struct.id_ref = 0.4F;

    /* Merge: '<S9>/Merge1' incorporates:
     *  Constant: '<S365>/Constant'
     *  SignalConversion generated from: '<S365>/Iq_Ref'
     */
    rt_Simulink_Struct.iq_ref = 0.0F;

    /* Merge: '<S9>/Merge2' incorporates:
     *  Constant: '<S365>/Constant2'
     *  SignalConversion generated from: '<S365>/Theta'
     */
    rt_Simulink_Struct.cal_theta = 0.0F;

    /* End of Outputs for SubSystem: '<S9>/Switch Case Action Subsystem' */
    break;

   case 1:
    {
      uint32_T SwitchCaseActionSubsystem1_ELAP;
      if (LBG_model_DW.SwitchCase_ActiveSubsystem != rtPrevAction) {
        LBG_model_DW.SwitchCaseActionSubsystem1_RESE = true;

        /* Enable for IfAction SubSystem: '<S9>/Switch Case Action Subsystem1' incorporates:
         *  ActionPort: '<S366>/Action Port'
         */
        /* Enable for SwitchCase: '<S9>/Switch Case' incorporates:
         *  DiscreteIntegrator: '<S366>/Discrete-Time Integrator'
         *  DiscreteIntegrator: '<S366>/Discrete-Time Integrator1'
         */
        LBG_model_DW.DiscreteTimeIntegrator1_SYSTE_m = 1U;
        LBG_model_DW.DiscreteTimeIntegrator_SYSTEM_n = 1U;

        /* End of Enable for SubSystem: '<S9>/Switch Case Action Subsystem1' */
      }

      /* Outputs for IfAction SubSystem: '<S9>/Switch Case Action Subsystem1' incorporates:
       *  ActionPort: '<S366>/Action Port'
       */
      if (LBG_model_DW.SwitchCaseActionSubsystem1_RESE) {
        SwitchCaseActionSubsystem1_ELAP = 0U;
      } else {
        SwitchCaseActionSubsystem1_ELAP = LBG_model_DW.FOC_PREV_T
          - LBG_model_DW.SwitchCaseActionSubsystem1_PREV;
      }

      LBG_model_DW.SwitchCaseActionSubsystem1_PREV = LBG_model_DW.FOC_PREV_T;
      LBG_model_DW.SwitchCaseActionSubsystem1_RESE = false;

      /* DiscreteIntegrator: '<S366>/Discrete-Time Integrator1' */
      if (LBG_model_DW.DiscreteTimeIntegrator1_SYSTE_m == 0) {
        /* DiscreteIntegrator: '<S366>/Discrete-Time Integrator1' */
        LBG_model_DW.DiscreteTimeIntegrator1_DSTAT_l += 5.0E-5F * (real32_T)
          SwitchCaseActionSubsystem1_ELAP *
          LBG_model_DW.DiscreteTimeIntegrator1_PREV__o;
      }

      /* End of DiscreteIntegrator: '<S366>/Discrete-Time Integrator1' */

      /* Merge: '<S9>/Merge' incorporates:
       *  Constant: '<S366>/Constant1'
       *  SignalConversion generated from: '<S366>/Id_Ref'
       */
      rt_Simulink_Struct.id_ref = 0.4F;

      /* Merge: '<S9>/Merge1' incorporates:
       *  Constant: '<S366>/Constant'
       *  SignalConversion generated from: '<S366>/Iq_Ref'
       */
      rt_Simulink_Struct.iq_ref = 0.0F;

      /* DiscreteIntegrator: '<S366>/Discrete-Time Integrator' */
      if (LBG_model_DW.DiscreteTimeIntegrator_SYSTEM_n == 0) {
        /* DiscreteIntegrator: '<S366>/Discrete-Time Integrator' */
        LBG_model_DW.DiscreteTimeIntegrator_DSTATE_e += 5.0E-5F * (real32_T)
          SwitchCaseActionSubsystem1_ELAP *
          LBG_model_DW.DiscreteTimeIntegrator_PREV__bg;
      }

      /* End of DiscreteIntegrator: '<S366>/Discrete-Time Integrator' */

      /* Merge: '<S9>/Merge2' incorporates:
       *  Constant: '<S366>/Constant4'
       *  Math: '<S366>/Math Function'
       *  SignalConversion generated from: '<S366>/Theta'
       */
      rt_Simulink_Struct.cal_theta = rt_modf_snf
        (LBG_model_DW.DiscreteTimeIntegrator1_DSTAT_l, 6.28318548F);

      /* Update for DiscreteIntegrator: '<S366>/Discrete-Time Integrator1' incorporates:
       *  Gain: '<S366>/Gain'
       *  Gain: '<S366>/Gain1'
       */
      LBG_model_DW.DiscreteTimeIntegrator1_SYSTE_m = 0U;
      LBG_model_DW.DiscreteTimeIntegrator1_PREV__o = 0.116666667F *
        LBG_model_DW.DiscreteTimeIntegrator_DSTATE_e * 6.28318548F;

      /* Update for DiscreteIntegrator: '<S366>/Discrete-Time Integrator' */
      LBG_model_DW.DiscreteTimeIntegrator_SYSTEM_n = 0U;
      LBG_model_DW.DiscreteTimeIntegrator_PREV__bg = LBG_model_ConstB.Divide_d;

      /* End of Outputs for SubSystem: '<S9>/Switch Case Action Subsystem1' */
    }
    break;

   case 2:
    /* Outputs for IfAction SubSystem: '<S9>/Switch Case Action Subsystem2' incorporates:
     *  ActionPort: '<S367>/Action Port'
     */
    /* Merge: '<S9>/Merge' incorporates:
     *  SignalConversion generated from: '<S367>/Id'
     */
    rt_Simulink_Struct.id_ref = LBG_model_B.OutportBufferForId_Ref;

    /* Merge: '<S9>/Merge1' incorporates:
     *  SignalConversion generated from: '<S367>/Iq'
     */
    rt_Simulink_Struct.iq_ref = LBG_model_B.Saturation;

    /* Merge: '<S9>/Merge2' incorporates:
     *  Delay: '<S3>/Delay'
     *  SignalConversion generated from: '<S367>/Obs_Theta'
     */
    rt_Simulink_Struct.cal_theta = LBG_model_DW.Delay_DSTATE_o;

    /* End of Outputs for SubSystem: '<S9>/Switch Case Action Subsystem2' */
    break;

   case 3:
    {
      uint32_T SwitchCaseActionSubsystem1_ELAP;
      if (LBG_model_DW.SwitchCase_ActiveSubsystem != rtPrevAction) {
        LBG_model_DW.SwitchCaseActionSubsystem3_RESE = true;

        /* Enable for IfAction SubSystem: '<S9>/Switch Case Action Subsystem3' incorporates:
         *  ActionPort: '<S368>/Action Port'
         */
        /* Enable for SwitchCase: '<S9>/Switch Case' incorporates:
         *  DiscreteIntegrator: '<S368>/Discrete-Time Integrator'
         *  DiscreteIntegrator: '<S368>/Discrete-Time Integrator1'
         */
        LBG_model_DW.DiscreteTimeIntegrator1_SYSTEM_ = 1U;
        LBG_model_DW.DiscreteTimeIntegrator_SYSTE_fz = 1U;

        /* End of Enable for SubSystem: '<S9>/Switch Case Action Subsystem3' */
      }

      /* Outputs for IfAction SubSystem: '<S9>/Switch Case Action Subsystem3' incorporates:
       *  ActionPort: '<S368>/Action Port'
       */
      if (LBG_model_DW.SwitchCaseActionSubsystem3_RESE) {
        SwitchCaseActionSubsystem1_ELAP = 0U;
      } else {
        SwitchCaseActionSubsystem1_ELAP = LBG_model_DW.FOC_PREV_T
          - LBG_model_DW.SwitchCaseActionSubsystem3_PREV;
      }

      LBG_model_DW.SwitchCaseActionSubsystem3_PREV = LBG_model_DW.FOC_PREV_T;
      LBG_model_DW.SwitchCaseActionSubsystem3_RESE = false;

      /* DiscreteIntegrator: '<S368>/Discrete-Time Integrator1' */
      if (LBG_model_DW.DiscreteTimeIntegrator1_SYSTEM_ == 0) {
        /* DiscreteIntegrator: '<S368>/Discrete-Time Integrator1' */
        LBG_model_DW.DiscreteTimeIntegrator1_DSTATE += 5.0E-5F * (real32_T)
          SwitchCaseActionSubsystem1_ELAP *
          LBG_model_DW.DiscreteTimeIntegrator1_PREV_U;
      }

      /* End of DiscreteIntegrator: '<S368>/Discrete-Time Integrator1' */

      /* Merge: '<S9>/Merge' incorporates:
       *  Constant: '<S368>/Constant1'
       *  SignalConversion generated from: '<S368>/Id_Ref'
       */
      rt_Simulink_Struct.id_ref = 0.4F;

      /* Merge: '<S9>/Merge1' incorporates:
       *  Constant: '<S368>/Constant'
       *  SignalConversion generated from: '<S368>/Iq_Ref'
       */
      rt_Simulink_Struct.iq_ref = 0.0F;

      /* DiscreteIntegrator: '<S368>/Discrete-Time Integrator' */
      if (LBG_model_DW.DiscreteTimeIntegrator_SYSTE_fz == 0) {
        /* DiscreteIntegrator: '<S368>/Discrete-Time Integrator' */
        LBG_model_DW.DiscreteTimeIntegrator_DSTATE_o += 5.0E-5F * (real32_T)
          SwitchCaseActionSubsystem1_ELAP *
          LBG_model_DW.DiscreteTimeIntegrator_PREV_U_b;
      }

      /* End of DiscreteIntegrator: '<S368>/Discrete-Time Integrator' */

      /* Merge: '<S9>/Merge2' incorporates:
       *  Constant: '<S368>/Constant4'
       *  Math: '<S368>/Math Function'
       *  SignalConversion generated from: '<S368>/Theta'
       */
      rt_Simulink_Struct.cal_theta = rt_modf_snf
        (LBG_model_DW.DiscreteTimeIntegrator1_DSTATE, 6.28318548F);

      /* Update for DiscreteIntegrator: '<S368>/Discrete-Time Integrator1' incorporates:
       *  Gain: '<S368>/Gain'
       *  Gain: '<S368>/Gain1'
       */
      LBG_model_DW.DiscreteTimeIntegrator1_SYSTEM_ = 0U;
      LBG_model_DW.DiscreteTimeIntegrator1_PREV_U = 0.116666667F *
        LBG_model_DW.DiscreteTimeIntegrator_DSTATE_o * 6.28318548F;

      /* Update for DiscreteIntegrator: '<S368>/Discrete-Time Integrator' */
      LBG_model_DW.DiscreteTimeIntegrator_SYSTE_fz = 0U;
      LBG_model_DW.DiscreteTimeIntegrator_PREV_U_b = LBG_model_ConstB.Divide;

      /* End of Outputs for SubSystem: '<S9>/Switch Case Action Subsystem3' */
    }
    break;
  }

  /* MATLAB Function: '<S7>/Park' */
  rtb_Sum2 = sinf(rt_Simulink_Struct.cal_theta);
  rtb_Sum3 = cosf(rt_Simulink_Struct.cal_theta);
  rt_Simulink_Struct.id_fbd = rtb_Sum_b * rtb_Sum3 + rtb_ibeta * rtb_Sum2;
  rt_Simulink_Struct.iq_fbd = -rtb_Sum_b * rtb_Sum2 + rtb_ibeta * rtb_Sum3;

  /* Sum: '<S7>/Sum2' */
  rtb_Sum2 = rt_Simulink_Struct.id_ref - rt_Simulink_Struct.id_fbd;

  /* DiscreteIntegrator: '<S282>/Integrator' */
  if (LBG_model_DW.Integrator_SYSTEM_ENABLE == 0) {
    /* DiscreteIntegrator: '<S282>/Integrator' */
    LBG_model_DW.Integrator_DSTATE += 5.0E-5F * (real32_T)elapsedTicks *
      LBG_model_DW.Integrator_PREV_U;
  }

  /* End of DiscreteIntegrator: '<S282>/Integrator' */

  /* Sum: '<S291>/Sum' incorporates:
   *  Gain: '<S287>/Proportional Gain'
   */
  rtb_Saturation = 0.485F * rtb_Sum2 + LBG_model_DW.Integrator_DSTATE;

  /* Saturate: '<S289>/Saturation' */
  if (rtb_Saturation > 6.92820311F) {
    rtb_Saturation = 6.92820311F;
  } else if (rtb_Saturation < -6.92820311F) {
    rtb_Saturation = -6.92820311F;
  }

  /* End of Saturate: '<S289>/Saturation' */

  /* Sum: '<S7>/Sum3' */
  rtb_Sum3 = rt_Simulink_Struct.iq_ref - rt_Simulink_Struct.iq_fbd;

  /* DiscreteIntegrator: '<S330>/Integrator' */
  if (LBG_model_DW.Integrator_SYSTEM_ENABLE_e == 0) {
    /* DiscreteIntegrator: '<S330>/Integrator' */
    LBG_model_DW.Integrator_DSTATE_c += 5.0E-5F * (real32_T)elapsedTicks *
      LBG_model_DW.Integrator_PREV_U_c;
  }

  /* End of DiscreteIntegrator: '<S330>/Integrator' */

  /* Sum: '<S339>/Sum' incorporates:
   *  Gain: '<S335>/Proportional Gain'
   */
  rtb_Saturation_l = 0.485F * rtb_Sum3 + LBG_model_DW.Integrator_DSTATE_c;

  /* Saturate: '<S337>/Saturation' */
  if (rtb_Saturation_l > 6.92820311F) {
    rtb_Saturation_l = 6.92820311F;
  } else if (rtb_Saturation_l < -6.92820311F) {
    rtb_Saturation_l = -6.92820311F;
  }

  /* End of Saturate: '<S337>/Saturation' */

  /* MATLAB Function: '<S7>/svpwm' incorporates:
   *  Constant: '<S7>/Constant'
   *  Constant: '<S7>/Constant1'
   */
  beta = atanf(rtb_Saturation_l / fabsf(rtb_Saturation));
  if (rtb_Saturation * rtb_Saturation + rtb_Saturation_l * rtb_Saturation_l >
      48.0F) {
    rtb_Tcmp3 = cosf(beta);
    rtb_Saturation = -6.92820311F * rtb_Tcmp3;
    rtb_Saturation_l = 6.92820311F * sinf(beta);
    if (rtb_Saturation > 0.0F) {
      rtb_Saturation = 6.92820311F * rtb_Tcmp3;
    }
  }

  rtb_Tcmp3 = sinf(rt_Simulink_Struct.cal_theta);
  rtb_Vbeta = cosf(rt_Simulink_Struct.cal_theta);
  beta = rtb_Saturation * rtb_Vbeta - rtb_Saturation_l * rtb_Tcmp3;
  rtb_Vbeta = rtb_Saturation * rtb_Tcmp3 + rtb_Saturation_l * rtb_Vbeta;
  rt_Simulink_Struct.cal_sector = 0;
  rtb_Saturation = 0.0F;
  rtb_Saturation_l = 0.0F;
  rtb_Tcmp3 = 0.0F;
  if (rtb_Vbeta > 0.0F) {
    rt_Simulink_Struct.cal_sector = 1;
  }

  if ((1.73205078F * beta - rtb_Vbeta) / 2.0F > 0.0F) {
    rt_Simulink_Struct.cal_sector = (int8_T)(rt_Simulink_Struct.cal_sector + 2);
  }

  if ((-1.73205078F * beta - rtb_Vbeta) / 2.0F > 0.0F) {
    rt_Simulink_Struct.cal_sector = (int8_T)(rt_Simulink_Struct.cal_sector + 4);
  }

  switch (rt_Simulink_Struct.cal_sector) {
   case 1:
    T1 = (-1.5F * beta + 0.866025388F * rtb_Vbeta) * 682.666687F;
    T2 = (1.5F * beta + 0.866025388F * rtb_Vbeta) * 682.666687F;
    break;

   case 2:
    T1 = (1.5F * beta + 0.866025388F * rtb_Vbeta) * 682.666687F;
    T2 = -(1.73205078F * rtb_Vbeta * 8192.0F / 12.0F);
    break;

   case 3:
    T1 = -((-1.5F * beta + 0.866025388F * rtb_Vbeta) * 682.666687F);
    T2 = 1.73205078F * rtb_Vbeta * 8192.0F / 12.0F;
    break;

   case 4:
    T1 = -(1.73205078F * rtb_Vbeta * 8192.0F / 12.0F);
    T2 = (-1.5F * beta + 0.866025388F * rtb_Vbeta) * 682.666687F;
    break;

   case 5:
    T1 = 1.73205078F * rtb_Vbeta * 8192.0F / 12.0F;
    T2 = -((1.5F * beta + 0.866025388F * rtb_Vbeta) * 682.666687F);
    break;

   default:
    T1 = -((1.5F * beta + 0.866025388F * rtb_Vbeta) * 682.666687F);
    T2 = -((-1.5F * beta + 0.866025388F * rtb_Vbeta) * 682.666687F);
    break;
  }

  ta = (8192.0F - (T1 + T2)) / 4.0F;
  T1 = T1 / 2.0F + ta;
  T2 = T2 / 2.0F + T1;
  ta = roundf(ta);
  T1 = roundf(T1);
  switch (rt_Simulink_Struct.cal_sector) {
   case 1:
    rtb_Saturation = T1;
    rtb_Saturation_l = ta;
    rtb_Tcmp3 = roundf(T2);
    break;

   case 2:
    rtb_Saturation = ta;
    rtb_Saturation_l = roundf(T2);
    rtb_Tcmp3 = T1;
    break;

   case 3:
    rtb_Saturation = ta;
    rtb_Saturation_l = T1;
    rtb_Tcmp3 = roundf(T2);
    break;

   case 4:
    rtb_Saturation = roundf(T2);
    rtb_Saturation_l = T1;
    rtb_Tcmp3 = ta;
    break;

   case 5:
    rtb_Saturation = roundf(T2);
    rtb_Saturation_l = ta;
    rtb_Tcmp3 = T1;
    break;

   case 6:
    rtb_Saturation = T1;
    rtb_Saturation_l = roundf(T2);
    rtb_Tcmp3 = ta;
    break;
  }

  /* End of MATLAB Function: '<S7>/svpwm' */

  /* Sum: '<S11>/Add4' incorporates:
   *  Constant: '<S11>/Constant10'
   *  Constant: '<S11>/Constant11'
   *  Constant: '<S11>/Constant9'
   *  Delay: '<S11>/Delay'
   *  Product: '<S11>/Product'
   *  Product: '<S11>/Product10'
   *  Product: '<S11>/Product11'
   *  Product: '<S11>/Product12'
   */
  LBG_model_DW.Delay_DSTATE_p = ((LBG_model_DW.Delay_DSTATE_p *
    LBG_model_ConstB.Add - 0.515463889F * rtb_Delay2) + 0.515463889F * beta) -
    -1.36607659F * rtb_Sum_b;

  /* Sum: '<S11>/Add6' incorporates:
   *  Constant: '<S11>/Constant13'
   *  Constant: '<S11>/Constant6'
   *  Constant: '<S11>/Constant7'
   *  Delay: '<S11>/Delay1'
   *  Product: '<S11>/Product4'
   *  Product: '<S11>/Product5'
   *  Product: '<S11>/Product6'
   *  Product: '<S11>/Product7'
   */
  LBG_model_DW.Delay1_DSTATE = ((LBG_model_DW.Delay1_DSTATE *
    LBG_model_ConstB.Add5 - 0.515463889F * rtb_Delay3) + 0.515463889F *
    rtb_Vbeta) - -1.36607659F * rtb_ibeta;

  /* Outputs for Atomic SubSystem: '<S12>/atan2' */
  /* Outputs for Enabled SubSystem: '<S22>/If Action Subsystem' incorporates:
   *  EnablePort: '<S85>/Enable'
   */
  /* Merge: '<S22>/Merge' incorporates:
   *  Delay: '<S11>/Delay2'
   *  Delay: '<S11>/Delay3'
   *  SignalConversion generated from: '<S85>/In1'
   *  Trigonometry: '<S22>/Atan2'
   */
  LBG_model_B.Merge_n = rt_atan2f_snf(LBG_model_DW.Delay2_DSTATE,
    LBG_model_DW.Delay3_DSTATE);

  /* End of Outputs for SubSystem: '<S22>/If Action Subsystem' */
  /* End of Outputs for SubSystem: '<S12>/atan2' */

  /* DiscreteIntegrator: '<S12>/Discrete-Time Integrator' */
  if (LBG_model_DW.DiscreteTimeIntegrator_SYSTEM_E == 0) {
    /* DiscreteIntegrator: '<S12>/Discrete-Time Integrator' */
    LBG_model_DW.DiscreteTimeIntegrator_DSTATE += 5.0E-5F * (real32_T)
      elapsedTicks * LBG_model_DW.DiscreteTimeIntegrator_PREV_U;
  }

  /* End of DiscreteIntegrator: '<S12>/Discrete-Time Integrator' */

  /* Math: '<S12>/Mod' incorporates:
   *  Constant: '<S12>/Constant1'
   *  Delay: '<S3>/Delay'
   */
  LBG_model_DW.Delay_DSTATE_o = rt_modf_snf
    (LBG_model_DW.DiscreteTimeIntegrator_DSTATE, 6.28318548F);

  /* MATLAB Function: '<S12>/MATLAB cos' incorporates:
   *  Delay: '<S3>/Delay'
   */
  LBG_model_MATLABcos(LBG_model_DW.Delay_DSTATE_o, &rtb_Delay2);

  /* Product: '<S12>/Product4' incorporates:
   *  Delay: '<S11>/Delay2'
   */
  rtb_Delay3 = LBG_model_DW.Delay2_DSTATE * rtb_Delay2;

  /* Sqrt: '<S12>/Sqrt' incorporates:
   *  Delay: '<S12>/Delay'
   *  Delay: '<S12>/Delay1'
   *  Math: '<S12>/Square'
   *  Math: '<S12>/Square1'
   *  Sum: '<S12>/Add1'
   */
  ta = sqrtf(LBG_model_DW.Delay_DSTATE_l * LBG_model_DW.Delay_DSTATE_l +
             LBG_model_DW.Delay1_DSTATE_j * LBG_model_DW.Delay1_DSTATE_j);

  /* Saturate: '<S12>/Saturation' */
  if (ta > 100.0F) {
    ta = 100.0F;
  } else if (ta < 0.001F) {
    ta = 0.001F;
  }

  /* End of Saturate: '<S12>/Saturation' */

  /* MATLAB Function: '<S12>/MATLAB sin' incorporates:
   *  Delay: '<S3>/Delay'
   */
  LBG_model_MATLABsin(LBG_model_DW.Delay_DSTATE_o, &rtb_Delay2);

  /* Sum: '<S12>/Add8' incorporates:
   *  Delay: '<S11>/Delay3'
   *  Product: '<S12>/Divide'
   *  Product: '<S12>/Divide1'
   *  Product: '<S12>/Product5'
   */
  ta = (0.0F - rtb_Delay3 / ta) - LBG_model_DW.Delay3_DSTATE * rtb_Delay2 / ta;

  /* DiscreteIntegrator: '<S63>/Integrator' */
  if (LBG_model_DW.Integrator_SYSTEM_ENABLE_d == 0) {
    /* DiscreteIntegrator: '<S63>/Integrator' */
    LBG_model_DW.Integrator_DSTATE_f += 5.0E-5F * (real32_T)elapsedTicks *
      LBG_model_DW.Integrator_PREV_U_d;
  }

  /* End of DiscreteIntegrator: '<S63>/Integrator' */

  /* Sum: '<S73>/Sum' incorporates:
   *  Constant: '<S12>/Constant23'
   *  Product: '<S68>/PProd Out'
   */
  rtb_Delay2 = ta * 2513.0F + LBG_model_DW.Integrator_DSTATE_f;

  /* Switch: '<S71>/Switch2' incorporates:
   *  Constant: '<S12>/Constant25'
   *  Constant: '<S12>/Constant26'
   *  RelationalOperator: '<S71>/LowerRelop1'
   *  RelationalOperator: '<S71>/UpperRelop'
   *  Switch: '<S71>/Switch'
   */
  if (rtb_Delay2 > 6283.18555F) {
    /* Switch: '<S71>/Switch2' */
    LBG_model_DW.DiscreteTimeIntegrator_PREV_U = 6283.18555F;
  } else if (rtb_Delay2 < -6283.18555F) {
    /* Switch: '<S71>/Switch2' incorporates:
     *  Constant: '<S12>/Constant26'
     *  Switch: '<S71>/Switch'
     */
    LBG_model_DW.DiscreteTimeIntegrator_PREV_U = -6283.18555F;
  } else {
    /* Switch: '<S71>/Switch2' incorporates:
     *  Switch: '<S71>/Switch'
     */
    LBG_model_DW.DiscreteTimeIntegrator_PREV_U = rtb_Delay2;
  }

  /* End of Switch: '<S71>/Switch2' */

  /* Gain: '<S12>/Gain2' */
  LBG_model_DW.Delay_DSTATE = 1.36418521F *
    LBG_model_DW.DiscreteTimeIntegrator_PREV_U;

  /* Gain: '<S12>/Gain4' incorporates:
   *  Gain: '<S12>/Gain3'
   *  Gain: '<S12>/f_2_we'
   */
  LBG_model_DW.Delay_DSTATE_g = 0.116666667F * LBG_model_DW.Delay_DSTATE *
    6.28318548F;

  /* Sum: '<S28>/Add1' incorporates:
   *  Constant: '<S28>/Filter_Constant'
   *  Constant: '<S28>/One'
   *  Product: '<S28>/Product'
   *  Product: '<S28>/Product1'
   */
  rt_Simulink_Struct.ob_spd = LBG_model_DW.Delay_DSTATE_g * 0.02F + 0.98F *
    rt_Simulink_Struct.ob_spd;

  /* MATLAB Function: '<S12>/MATLAB Function' incorporates:
   *  Inport: '<Root>/Target_Speed'
   */
  if (arg_Target_Speed >= 0.0F) {
    rtb_Delay3 = 0.0F;
  } else {
    rtb_Delay3 = -3.14159274F;
  }

  /* Outputs for Atomic SubSystem: '<S12>/atan2' */
  /* Math: '<S12>/Math Function' incorporates:
   *  AlgorithmDescriptorDelegate generated from: '<S22>/a16'
   *  Constant: '<S12>/Constant'
   *  Gain: '<S12>/Gain'
   *  MATLAB Function: '<S12>/MATLAB Function'
   *  Sum: '<S12>/Add'
   */
  rt_Simulink_Struct.ob_theta = rt_modf_snf(-LBG_model_B.Merge_n + rtb_Delay3,
    6.28318548F);

  /* End of Outputs for SubSystem: '<S12>/atan2' */

  /* Switch: '<S56>/Switch' incorporates:
   *  Constant: '<S12>/Constant25'
   *  Constant: '<S12>/Constant26'
   *  RelationalOperator: '<S56>/u_GTE_up'
   *  RelationalOperator: '<S56>/u_GT_lo'
   *  Switch: '<S56>/Switch1'
   */
  if (rtb_Delay2 >= 6283.18555F) {
    rtb_Delay3 = 6283.18555F;
  } else if (rtb_Delay2 > -6283.18555F) {
    /* Switch: '<S56>/Switch1' */
    rtb_Delay3 = rtb_Delay2;
  } else {
    rtb_Delay3 = -6283.18555F;
  }

  /* Sum: '<S56>/Diff' incorporates:
   *  Switch: '<S56>/Switch'
   */
  T2 = rtb_Delay2 - rtb_Delay3;

  /* Product: '<S60>/IProd Out' incorporates:
   *  Constant: '<S12>/Constant24'
   */
  ta *= 1.579136E+6F;

  /* Switch: '<S53>/Switch1' incorporates:
   *  Constant: '<S53>/Clamping_zero'
   *  Constant: '<S53>/Constant'
   *  Constant: '<S53>/Constant2'
   *  RelationalOperator: '<S53>/fix for DT propagation issue'
   */
  if (T2 > 0.0F) {
    rtPrevAction = 1;
  } else {
    rtPrevAction = -1;
  }

  /* Switch: '<S53>/Switch2' incorporates:
   *  Constant: '<S53>/Clamping_zero'
   *  Constant: '<S53>/Constant3'
   *  Constant: '<S53>/Constant4'
   *  RelationalOperator: '<S53>/fix for DT propagation issue1'
   */
  if (ta > 0.0F) {
    tmp = 1;
  } else {
    tmp = -1;
  }

  /* Switch: '<S53>/Switch' incorporates:
   *  Constant: '<S53>/Clamping_zero'
   *  Logic: '<S53>/AND3'
   *  RelationalOperator: '<S53>/Equal1'
   *  RelationalOperator: '<S53>/Relational Operator'
   *  Switch: '<S53>/Switch1'
   *  Switch: '<S53>/Switch2'
   */
  if ((T2 != 0.0F) && (rtPrevAction == tmp)) {
    /* Update for DiscreteIntegrator: '<S63>/Integrator' incorporates:
     *  Constant: '<S53>/Constant1'
     */
    LBG_model_DW.Integrator_PREV_U_d = 0.0F;
  } else {
    /* Update for DiscreteIntegrator: '<S63>/Integrator' */
    LBG_model_DW.Integrator_PREV_U_d = ta;
  }

  /* End of Switch: '<S53>/Switch' */

  /* Sum: '<S13>/Sum' incorporates:
   *  Delay: '<S10>/Delay1'
   *  Delay: '<S13>/Delay'
   *  Gain: '<S13>/Gain1'
   */
  ta = LBG_model_DW.Delay_DSTATE_f - 9.7E-5F * LBG_model_DW.Delay1_DSTATE_c;

  /* Abs: '<S13>/Abs' */
  T2 = fabsf(ta);

  /* Sum: '<S13>/Sum1' incorporates:
   *  Delay: '<S10>/Delay3'
   *  Delay: '<S13>/Delay1'
   *  Gain: '<S13>/Gain3'
   */
  rtb_Delay3 = LBG_model_DW.Delay1_DSTATE_b - 9.7E-5F *
    LBG_model_DW.Delay3_DSTATE_f;

  /* Abs: '<S13>/Abs1' */
  rtb_Delay2 = fabsf(rtb_Delay3);

  /* Sum: '<S13>/Add3' incorporates:
   *  Math: '<S13>/Square1'
   *  Math: '<S13>/Square2'
   *  Sum: '<S13>/Add1'
   */
  rtb_Delay2 = LBG_model_ConstB.Square3 - (T2 * T2 + rtb_Delay2 * rtb_Delay2);

  /* Sum: '<S13>/Add5' incorporates:
   *  Constant: '<S13>/Constant1'
   *  Delay: '<S10>/Delay1'
   *  Delay: '<S10>/Delay2'
   *  Delay: '<S13>/Delay'
   *  Gain: '<S13>/Gain'
   *  Gain: '<S13>/Gain4'
   *  Product: '<S13>/Product'
   *  Sum: '<S13>/Add'
   *  Sum: '<S13>/Add4'
   */
  LBG_model_DW.Delay_DSTATE_f += ((LBG_model_DW.Delay2_DSTATE_a - 0.194F *
    LBG_model_DW.Delay1_DSTATE_c) + 1.0E+10F * ta * rtb_Delay2) * 5.0E-5F;

  /* Sum: '<S13>/Add8' incorporates:
   *  Constant: '<S13>/Constant2'
   *  Delay: '<S10>/Delay3'
   *  Delay: '<S10>/Delay4'
   *  Delay: '<S13>/Delay1'
   *  Gain: '<S13>/Gain2'
   *  Gain: '<S13>/Gain7'
   *  Product: '<S13>/Product1'
   *  Sum: '<S13>/Add2'
   *  Sum: '<S13>/Add7'
   */
  LBG_model_DW.Delay1_DSTATE_b += (rtb_Delay2 * rtb_Delay3 * 1.0E+10F +
    (LBG_model_DW.Delay4_DSTATE - 0.194F * LBG_model_DW.Delay3_DSTATE_f)) *
    5.0E-5F;

  /* DiscreteIntegrator: '<S14>/Discrete-Time Integrator' */
  if (LBG_model_DW.DiscreteTimeIntegrator_SYSTEM_f == 0) {
    /* DiscreteIntegrator: '<S14>/Discrete-Time Integrator' */
    LBG_model_DW.DiscreteTimeIntegrator_DSTATE_p += 5.0E-5F * (real32_T)
      elapsedTicks * LBG_model_DW.DiscreteTimeIntegrator_PREV_U_i;
  }

  /* End of DiscreteIntegrator: '<S14>/Discrete-Time Integrator' */

  /* Math: '<S14>/Mod' incorporates:
   *  Constant: '<S14>/Constant1'
   */
  ta = rt_modf_snf(LBG_model_DW.DiscreteTimeIntegrator_DSTATE_p, 6.28318548F);

  /* MATLAB Function: '<S14>/MATLAB sin' */
  LBG_model_MATLABsin(ta, &rtb_Delay2);

  /* MATLAB Function: '<S14>/MATLAB cos' */
  LBG_model_MATLABcos(ta, &rtb_Delay3);

  /* Sum: '<S14>/Add8' incorporates:
   *  Delay: '<S10>/Delay1'
   *  Delay: '<S10>/Delay3'
   *  Delay: '<S13>/Delay'
   *  Delay: '<S13>/Delay1'
   *  Gain: '<S13>/Gain5'
   *  Gain: '<S13>/Gain6'
   *  Gain: '<S13>/Gain8'
   *  Gain: '<S13>/Gain9'
   *  Product: '<S14>/Product4'
   *  Product: '<S14>/Product5'
   *  Sum: '<S13>/Add6'
   *  Sum: '<S13>/Add9'
   */
  rtb_Delay2 = (LBG_model_DW.Delay1_DSTATE_b - 9.7E-5F *
                LBG_model_DW.Delay3_DSTATE_f) * 950.570312F * rtb_Delay3 -
    (LBG_model_DW.Delay_DSTATE_f - 9.7E-5F * LBG_model_DW.Delay1_DSTATE_c) *
    950.570312F * rtb_Delay2;

  /* DiscreteIntegrator: '<S124>/Integrator' */
  if (LBG_model_DW.Integrator_SYSTEM_ENABLE_l == 0) {
    /* DiscreteIntegrator: '<S124>/Integrator' */
    LBG_model_DW.Integrator_DSTATE_m += 5.0E-5F * (real32_T)elapsedTicks *
      LBG_model_DW.Integrator_PREV_U_b;
  }

  /* End of DiscreteIntegrator: '<S124>/Integrator' */

  /* Sum: '<S134>/Sum' incorporates:
   *  Constant: '<S14>/Constant23'
   *  Product: '<S129>/PProd Out'
   */
  LBG_model_DW.DiscreteTimeIntegrator_PREV_U_i = rtb_Delay2 * 2513.0F +
    LBG_model_DW.Integrator_DSTATE_m;

  /* Switch: '<S117>/Switch' incorporates:
   *  Constant: '<S14>/Constant25'
   *  Constant: '<S14>/Constant26'
   *  RelationalOperator: '<S117>/u_GTE_up'
   *  RelationalOperator: '<S117>/u_GT_lo'
   *  Switch: '<S117>/Switch1'
   */
  if (LBG_model_DW.DiscreteTimeIntegrator_PREV_U_i >= 6283.18555F) {
    rtb_Delay3 = 6283.18555F;
  } else if (LBG_model_DW.DiscreteTimeIntegrator_PREV_U_i > -6283.18555F) {
    /* Switch: '<S117>/Switch1' */
    rtb_Delay3 = LBG_model_DW.DiscreteTimeIntegrator_PREV_U_i;
  } else {
    rtb_Delay3 = -6283.18555F;
  }

  /* Sum: '<S117>/Diff' incorporates:
   *  Switch: '<S117>/Switch'
   */
  rtb_Delay3 = LBG_model_DW.DiscreteTimeIntegrator_PREV_U_i - rtb_Delay3;

  /* Product: '<S121>/IProd Out' incorporates:
   *  Constant: '<S14>/Constant24'
   */
  rtb_Delay2 *= 1.579136E+6F;

  /* Switch: '<S114>/Switch1' incorporates:
   *  Constant: '<S114>/Clamping_zero'
   *  Constant: '<S114>/Constant'
   *  Constant: '<S114>/Constant2'
   *  RelationalOperator: '<S114>/fix for DT propagation issue'
   */
  if (rtb_Delay3 > 0.0F) {
    rtPrevAction = 1;
  } else {
    rtPrevAction = -1;
  }

  /* Switch: '<S114>/Switch2' incorporates:
   *  Constant: '<S114>/Clamping_zero'
   *  Constant: '<S114>/Constant3'
   *  Constant: '<S114>/Constant4'
   *  RelationalOperator: '<S114>/fix for DT propagation issue1'
   */
  if (rtb_Delay2 > 0.0F) {
    tmp = 1;
  } else {
    tmp = -1;
  }

  /* Switch: '<S114>/Switch' incorporates:
   *  Constant: '<S114>/Clamping_zero'
   *  Logic: '<S114>/AND3'
   *  RelationalOperator: '<S114>/Equal1'
   *  RelationalOperator: '<S114>/Relational Operator'
   *  Switch: '<S114>/Switch1'
   *  Switch: '<S114>/Switch2'
   */
  if ((rtb_Delay3 != 0.0F) && (rtPrevAction == tmp)) {
    /* Update for DiscreteIntegrator: '<S124>/Integrator' incorporates:
     *  Constant: '<S114>/Constant1'
     */
    LBG_model_DW.Integrator_PREV_U_b = 0.0F;
  } else {
    /* Update for DiscreteIntegrator: '<S124>/Integrator' */
    LBG_model_DW.Integrator_PREV_U_b = rtb_Delay2;
  }

  /* End of Switch: '<S114>/Switch' */

  /* Switch: '<S132>/Switch2' incorporates:
   *  Constant: '<S14>/Constant25'
   *  Constant: '<S14>/Constant26'
   *  RelationalOperator: '<S132>/LowerRelop1'
   *  RelationalOperator: '<S132>/UpperRelop'
   *  Switch: '<S132>/Switch'
   */
  if (LBG_model_DW.DiscreteTimeIntegrator_PREV_U_i > 6283.18555F) {
    /* Sum: '<S134>/Sum' incorporates:
     *  DiscreteIntegrator: '<S14>/Discrete-Time Integrator'
     */
    LBG_model_DW.DiscreteTimeIntegrator_PREV_U_i = 6283.18555F;
  } else if (LBG_model_DW.DiscreteTimeIntegrator_PREV_U_i < -6283.18555F) {
    /* Sum: '<S134>/Sum' incorporates:
     *  Constant: '<S14>/Constant26'
     *  DiscreteIntegrator: '<S14>/Discrete-Time Integrator'
     *  Switch: '<S132>/Switch'
     */
    LBG_model_DW.DiscreteTimeIntegrator_PREV_U_i = -6283.18555F;
  }

  /* End of Switch: '<S132>/Switch2' */

  /* Gain: '<S356>/convert_pu' */
  rtb_Delay2 = 0.159154937F * rt_Simulink_Struct.cal_theta;

  /* If: '<S356>/If' incorporates:
   *  Constant: '<S357>/Constant'
   *  RelationalOperator: '<S357>/Compare'
   */
  if (rtb_Delay2 < 0.0F) {
    /* Outputs for IfAction SubSystem: '<S356>/If Action Subsystem' incorporates:
     *  ActionPort: '<S358>/Action Port'
     */
    /* DataTypeConversion: '<S358>/Convert_uint16' */
    rtb_Delay3 = floorf(rtb_Delay2);
    if (rtIsInfF(rtb_Delay3)) {
      rtb_Delay3 = 0.0F;
    } else {
      rtb_Delay3 = fmodf(rtb_Delay3, 65536.0F);
    }

    /* Sum: '<S358>/Sum' incorporates:
     *  DataTypeConversion: '<S358>/Convert_back'
     *  DataTypeConversion: '<S358>/Convert_uint16'
     */
    rtb_Delay2 -= (real32_T)(rtb_Delay3 < 0.0F ? (int32_T)(int16_T)-(int16_T)
      (uint16_T)-rtb_Delay3 : (int32_T)(int16_T)(uint16_T)rtb_Delay3);

    /* End of Outputs for SubSystem: '<S356>/If Action Subsystem' */
  } else {
    /* Outputs for IfAction SubSystem: '<S356>/If Action Subsystem1' incorporates:
     *  ActionPort: '<S359>/Action Port'
     */
    /* DataTypeConversion: '<S359>/Convert_uint16' */
    rtb_Delay3 = truncf(rtb_Delay2);
    if (rtIsNaNF(rtb_Delay3) || rtIsInfF(rtb_Delay3)) {
      rtb_Delay3 = 0.0F;
    } else {
      rtb_Delay3 = fmodf(rtb_Delay3, 65536.0F);
    }

    /* Sum: '<S359>/Sum' incorporates:
     *  DataTypeConversion: '<S359>/Convert_back'
     *  DataTypeConversion: '<S359>/Convert_uint16'
     */
    rtb_Delay2 -= (real32_T)(int16_T)(uint16_T)rtb_Delay3;

    /* End of Outputs for SubSystem: '<S356>/If Action Subsystem1' */
  }

  /* End of If: '<S356>/If' */

  /* Gain: '<S151>/indexing' */
  rtb_Delay2 *= 800.0F;

  /* DataTypeConversion: '<S151>/Get_Integer' */
  rtb_Delay3 = truncf(rtb_Delay2);
  if (rtIsNaNF(rtb_Delay3) || rtIsInfF(rtb_Delay3)) {
    rtb_Delay3 = 0.0F;
  } else {
    rtb_Delay3 = fmodf(rtb_Delay3, 65536.0F);
  }

  rtb_Get_Integer = (uint16_T)(rtb_Delay3 < 0.0F ? (int32_T)(uint16_T)-(int16_T)
    (uint16_T)-rtb_Delay3 : (int32_T)(uint16_T)rtb_Delay3);

  /* End of DataTypeConversion: '<S151>/Get_Integer' */

  /* Sum: '<S151>/Sum2' incorporates:
   *  DataTypeConversion: '<S151>/Data Type Conversion1'
   */
  ta = rtb_Delay2 - (real32_T)rtb_Get_Integer;

  /* Selector: '<S151>/Lookup' incorporates:
   *  Constant: '<S151>/sine_table_values'
   *  Sum: '<S151>/Sum'
   */
  rtb_Delay2 = LBG_model_ConstP.sine_table_values_Value[rtb_Get_Integer];

  /* Sum: '<S355>/Sum4' incorporates:
   *  Constant: '<S151>/offset'
   *  Constant: '<S151>/sine_table_values'
   *  Product: '<S355>/Product'
   *  Selector: '<S151>/Lookup'
   *  Sum: '<S151>/Sum'
   *  Sum: '<S355>/Sum3'
   */
  T2 = (LBG_model_ConstP.sine_table_values_Value[(int32_T)(rtb_Get_Integer + 1U)]
        - rtb_Delay2) * ta + rtb_Delay2;

  /* Selector: '<S151>/Lookup' incorporates:
   *  Constant: '<S151>/offset'
   *  Constant: '<S151>/sine_table_values'
   *  Sum: '<S151>/Sum'
   *  Sum: '<S355>/Sum5'
   */
  rtb_Delay2 = LBG_model_ConstP.sine_table_values_Value[(int32_T)
    (rtb_Get_Integer + 200U)];

  /* Sum: '<S355>/Sum6' incorporates:
   *  Constant: '<S151>/offset'
   *  Constant: '<S151>/sine_table_values'
   *  Product: '<S355>/Product1'
   *  Selector: '<S151>/Lookup'
   *  Sum: '<S151>/Sum'
   *  Sum: '<S355>/Sum5'
   */
  ta = (LBG_model_ConstP.sine_table_values_Value[(int32_T)(rtb_Get_Integer +
         201U)] - rtb_Delay2) * ta + rtb_Delay2;

  /* Outputs for Atomic SubSystem: '<S7>/Park Transform' */
  /* Sum: '<S7>/Sum' incorporates:
   *  Product: '<S150>/acos'
   *  Product: '<S150>/bsin'
   *  Sum: '<S150>/sum_Ds'
   */
  rtb_Delay2 = rt_Simulink_Struct.id_ref - (rtb_Sum_b * ta + rtb_ibeta * T2);

  /* End of Outputs for SubSystem: '<S7>/Park Transform' */

  /* DiscreteIntegrator: '<S186>/Integrator' */
  if (LBG_model_DW.Integrator_SYSTEM_ENABLE_g == 0) {
    /* DiscreteIntegrator: '<S186>/Integrator' */
    LBG_model_DW.Integrator_DSTATE_p += 5.0E-5F * (real32_T)elapsedTicks *
      LBG_model_DW.Integrator_PREV_U_c2;
  }

  /* End of DiscreteIntegrator: '<S186>/Integrator' */

  /* Sum: '<S195>/Sum' incorporates:
   *  Gain: '<S191>/Proportional Gain'
   */
  T1 = 0.485F * rtb_Delay2 + LBG_model_DW.Integrator_DSTATE_p;

  /* Saturate: '<S193>/Saturation' */
  if (T1 > 6.92820311F) {
    T1 = 6.92820311F;
  } else if (T1 < -6.92820311F) {
    T1 = -6.92820311F;
  }

  /* End of Saturate: '<S193>/Saturation' */

  /* Outputs for Atomic SubSystem: '<S7>/Park Transform' */
  /* Sum: '<S7>/Sum1' incorporates:
   *  Product: '<S150>/asin'
   *  Product: '<S150>/bcos'
   *  Sum: '<S150>/sum_Qs'
   */
  rtb_Delay3 = rt_Simulink_Struct.iq_ref - (rtb_ibeta * ta - rtb_Sum_b * T2);

  /* End of Outputs for SubSystem: '<S7>/Park Transform' */

  /* DiscreteIntegrator: '<S234>/Integrator' */
  if (LBG_model_DW.Integrator_SYSTEM_ENABLE_m == 0) {
    /* DiscreteIntegrator: '<S234>/Integrator' */
    LBG_model_DW.Integrator_DSTATE_mi += 5.0E-5F * (real32_T)elapsedTicks *
      LBG_model_DW.Integrator_PREV_U_b5;
  }

  /* End of DiscreteIntegrator: '<S234>/Integrator' */

  /* Sum: '<S243>/Sum' incorporates:
   *  Gain: '<S239>/Proportional Gain'
   */
  rtb_Saturation_o = 0.485F * rtb_Delay3 + LBG_model_DW.Integrator_DSTATE_mi;

  /* Saturate: '<S241>/Saturation' */
  if (rtb_Saturation_o > 6.92820311F) {
    rtb_Saturation_o = 6.92820311F;
  } else if (rtb_Saturation_o < -6.92820311F) {
    rtb_Saturation_o = -6.92820311F;
  }

  /* End of Saturate: '<S241>/Saturation' */

  /* Outputs for Atomic SubSystem: '<S7>/Inverse Park Transform' */
  /* AlgorithmDescriptorDelegate generated from: '<S147>/a16' incorporates:
   *  Product: '<S147>/dcos'
   *  Product: '<S147>/dsin'
   *  Product: '<S147>/qcos'
   *  Product: '<S147>/qsin'
   *  Sum: '<S147>/sum_alpha'
   *  Sum: '<S147>/sum_beta'
   */
  rtb_algDD_o1_m = T1 * ta - rtb_Saturation_o * T2;
  ta = rtb_Saturation_o * ta + T1 * T2;

  /* End of Outputs for SubSystem: '<S7>/Inverse Park Transform' */
  /* Update for SwitchCase: '<S9>/Switch Case' */
  switch (LBG_model_DW.SwitchCase_ActiveSubsystem) {
   case 0:
   case 2:
    break;

   case 1:
    /* Update for IfAction SubSystem: '<S9>/Switch Case Action Subsystem1' incorporates:
     *  ActionPort: '<S366>/Action Port'
     */
    LBG_model_DW.SwitchCaseActionSubsystem1_PREV = LBG_model_DW.FOC_PREV_T;
    LBG_model_DW.SwitchCaseActionSubsystem1_RESE = false;

    /* End of Update for SubSystem: '<S9>/Switch Case Action Subsystem1' */
    break;

   case 3:
    /* Update for IfAction SubSystem: '<S9>/Switch Case Action Subsystem3' incorporates:
     *  ActionPort: '<S368>/Action Port'
     */
    LBG_model_DW.SwitchCaseActionSubsystem3_PREV = LBG_model_DW.FOC_PREV_T;
    LBG_model_DW.SwitchCaseActionSubsystem3_RESE = false;

    /* End of Update for SubSystem: '<S9>/Switch Case Action Subsystem3' */
    break;
  }

  /* Update for DiscreteIntegrator: '<S282>/Integrator' incorporates:
   *  Gain: '<S279>/Integral Gain'
   */
  LBG_model_DW.Integrator_SYSTEM_ENABLE = 0U;
  LBG_model_DW.Integrator_PREV_U = 970.0F * rtb_Sum2;

  /* Update for DiscreteIntegrator: '<S330>/Integrator' incorporates:
   *  Gain: '<S327>/Integral Gain'
   */
  LBG_model_DW.Integrator_SYSTEM_ENABLE_e = 0U;
  LBG_model_DW.Integrator_PREV_U_c = 970.0F * rtb_Sum3;

  /* Update for Delay: '<S12>/Delay' incorporates:
   *  Delay: '<S11>/Delay2'
   */
  LBG_model_DW.Delay_DSTATE_l = LBG_model_DW.Delay2_DSTATE;

  /* Update for Delay: '<S12>/Delay1' incorporates:
   *  Delay: '<S11>/Delay3'
   */
  LBG_model_DW.Delay1_DSTATE_j = LBG_model_DW.Delay3_DSTATE;

  /* Update for DiscreteIntegrator: '<S12>/Discrete-Time Integrator' */
  LBG_model_DW.DiscreteTimeIntegrator_SYSTEM_E = 0U;

  /* Update for DiscreteIntegrator: '<S63>/Integrator' */
  LBG_model_DW.Integrator_SYSTEM_ENABLE_d = 0U;

  /* Update for Delay: '<S10>/Delay1' */
  LBG_model_DW.Delay1_DSTATE_c = rtb_Sum_b;

  /* Update for Delay: '<S10>/Delay2' */
  LBG_model_DW.Delay2_DSTATE_a = beta;

  /* Update for Delay: '<S10>/Delay3' */
  LBG_model_DW.Delay3_DSTATE_f = rtb_ibeta;

  /* Update for Delay: '<S10>/Delay4' */
  LBG_model_DW.Delay4_DSTATE = rtb_Vbeta;

  /* Update for DiscreteIntegrator: '<S14>/Discrete-Time Integrator' */
  LBG_model_DW.DiscreteTimeIntegrator_SYSTEM_f = 0U;

  /* Update for DiscreteIntegrator: '<S124>/Integrator' */
  LBG_model_DW.Integrator_SYSTEM_ENABLE_l = 0U;

  /* Update for DiscreteIntegrator: '<S186>/Integrator' incorporates:
   *  Gain: '<S183>/Integral Gain'
   */
  LBG_model_DW.Integrator_SYSTEM_ENABLE_g = 0U;
  LBG_model_DW.Integrator_PREV_U_c2 = 970.0F * rtb_Delay2;

  /* Update for DiscreteIntegrator: '<S234>/Integrator' incorporates:
   *  Gain: '<S231>/Integral Gain'
   */
  LBG_model_DW.Integrator_SYSTEM_ENABLE_m = 0U;
  LBG_model_DW.Integrator_PREV_U_b5 = 970.0F * rtb_Delay3;

  /* Outport: '<Root>/Vabc_PU' incorporates:
   *  Constant: '<S7>/Constant3'
   *  Gain: '<S7>/Gain1'
   *  Sum: '<S7>/Sum5'
   */
  arg_Vabc_PU[0] = 1.0F - 0.000244140625F * rtb_Saturation;
  arg_Vabc_PU[1] = 1.0F - 0.000244140625F * rtb_Saturation_l;
  arg_Vabc_PU[2] = 1.0F - 0.000244140625F * rtb_Tcmp3;

  /* End of Outputs for S-Function (fcgen): '<S1>/Function-Call Generator4' */

  /* Update absolute time for base rate */
  /* The "clockTick0" counts the number of times the code of this task has
   * been executed. The resolution of this integer timer is 5.0E-5, which is the step size
   * of the task. Size of "clockTick0" ensures timer will not overflow during the
   * application lifespan selected.
   */
  LBG_model_M->Timing.clockTick0++;
  if (LBG_model_M->Timing.TaskCounters.TID[1] == 0) {
    /* Update absolute timer for sample time: [0.001s, 0.0s] */
    /* The "clockTick1" counts the number of times the code of this task has
     * been executed. The resolution of this integer timer is 0.001, which is the step size
     * of the task. Size of "clockTick1" ensures timer will not overflow during the
     * application lifespan selected.
     */
    LBG_model_M->Timing.clockTick1++;
  }

  if (LBG_model_M->Timing.TaskCounters.TID[2] == 0) {
    /* Update absolute timer for sample time: [0.01s, 0.0s] */
    /* The "clockTick2" counts the number of times the code of this task has
     * been executed. The resolution of this integer timer is 0.01, which is the step size
     * of the task. Size of "clockTick2" ensures timer will not overflow during the
     * application lifespan selected.
     */
    LBG_model_M->Timing.clockTick2++;
  }

  rate_scheduler();
}

/* Model initialize function */
void LBG_Arctan_FOC_initialize(void)
{
  /* Registration code */

  /* initialize non-finites */
  rt_InitInfAndNaN(sizeof(real_T));

  /* SystemInitialize for S-Function (fcgen): '<S1>/Function-Call Generator3' incorporates:
   *  SubSystem: '<S1>/Speed_Control'
   */
  /* SystemInitialize for Enabled SubSystem: '<S4>/Subsystem' */
  /* SystemInitialize for SignalConversion generated from: '<S370>/Id_Ref' */
  LBG_model_B.OutportBufferForId_Ref = LBG_model_ConstB.Constant;

  /* End of SystemInitialize for SubSystem: '<S4>/Subsystem' */
  /* End of SystemInitialize for S-Function (fcgen): '<S1>/Function-Call Generator3' */
  /* Start for SwitchCase: '<S9>/Switch Case' */
  LBG_model_DW.SwitchCase_ActiveSubsystem = -1;

  /* End of SystemInitialize for S-Function (fcgen): '<S1>/Function-Call Generator4' */

  /* Enable for S-Function (fcgen): '<S1>/Function-Call Generator5' incorporates:
   *  SubSystem: '<S1>/10ms_Task'
   */
  /* Enable for Chart: '<S2>/Chart' */
  LBG_model_DW.previousTicks = LBG_model_M->Timing.clockTick2;

  /* End of Enable for S-Function (fcgen): '<S1>/Function-Call Generator5' */

  /* Enable for S-Function (fcgen): '<S1>/Function-Call Generator4' incorporates:
   *  SubSystem: '<S1>/FOC'
   */
  LBG_model_DW.FOC_RESET_ELAPS_T = true;

  /* Enable for DiscreteIntegrator: '<S282>/Integrator' */
  LBG_model_DW.Integrator_SYSTEM_ENABLE = 1U;

  /* Enable for DiscreteIntegrator: '<S330>/Integrator' */
  LBG_model_DW.Integrator_SYSTEM_ENABLE_e = 1U;

  /* Enable for DiscreteIntegrator: '<S12>/Discrete-Time Integrator' */
  LBG_model_DW.DiscreteTimeIntegrator_SYSTEM_E = 1U;

  /* Enable for DiscreteIntegrator: '<S63>/Integrator' */
  LBG_model_DW.Integrator_SYSTEM_ENABLE_d = 1U;

  /* Enable for DiscreteIntegrator: '<S14>/Discrete-Time Integrator' */
  LBG_model_DW.DiscreteTimeIntegrator_SYSTEM_f = 1U;

  /* Enable for DiscreteIntegrator: '<S124>/Integrator' */
  LBG_model_DW.Integrator_SYSTEM_ENABLE_l = 1U;

  /* Enable for DiscreteIntegrator: '<S186>/Integrator' */
  LBG_model_DW.Integrator_SYSTEM_ENABLE_g = 1U;

  /* Enable for DiscreteIntegrator: '<S234>/Integrator' */
  LBG_model_DW.Integrator_SYSTEM_ENABLE_m = 1U;

  /* End of Enable for S-Function (fcgen): '<S1>/Function-Call Generator4' */
}

/* Model terminate function */
void LBG_model_terminate(void)
{
  /* (no terminate code required) */
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
